package com.doradance.app.appactivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.text.style.EasyEditSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import com.doradance.R;
import com.doradance.app.MainActivity;
import com.pachong.android.baseuicomponent.activity.BaseActivity;
import com.pachong.android.frameworkbase.utils.EasyToast;

import butterknife.Bind;

public class NickNameActivity extends BaseActivity {

    public final static int MODIFYNICKNAME = 5;
    public final static int BACKMODIFYNICKNAME = 6;
    @Bind(R.id.et_nick_name)
    EditText mEtNickName;
    private String nickback;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initToolsBar();
        // 获取编辑框焦点
        mEtNickName.setFocusable(true);
        nickback = getIntent().getExtras().getString("nickname");
        Log.e("11111",nickback);
        if(nickback.equals("尚未设置昵称")){
            mEtNickName.setText("");
        }else{
            mEtNickName.setText(nickback);
        }

    }

    private void initToolsBar() {
        setTitle(getString(R.string.modify_nick_name));
        getCustomToolbar().addLeftImageButton(R.mipmap.back, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        getCustomToolbar().addRightButton("保存", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if(TextUtils.isEmpty(mEtNickName.getText().toString().trim())){
                    EasyToast.showToast(getApplicationContext(),"请输入昵称");
                }
                Intent intent = new Intent();
                // 获取用户计算后的结果
                intent.putExtra("nickback", mEtNickName.getText().toString().trim()); //将计算的值回传回去
                //通过intent对象返回结果，必须要调用一个setResult方法，
                //setResult(resultCode, data);第一个参数表示结果返回码，一般只要大于1就可以，但是
                setResult(BACKMODIFYNICKNAME, intent);
                finish(); //结束当前的activity的生命周期
            }
        });
    }

    public static void start(Activity activty,String name) {
        Intent intent = new Intent(activty, NickNameActivity.class);
        intent.putExtra("nickname",name);
        activty.startActivityForResult(intent, MODIFYNICKNAME);
    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.activity_nick_name, null);
    }
}
